package extend.db.base;

import extend.db.entity.Entity;
import extend.db.entity.annotation.EntityMetadata;
import hehe.log.Log;

/**
 * @todo 这里写类名
 * <B>说明：</B>
 * <pre>
 *  略
 * </pre>
 * <B>示例：</B>
 * <pre>
 *  略
 * </pre>
 * <B>日志：</B>
 * <pre>
 *  略
 * </pre>
 * <B>注意事项：</B>
 * <pre>
 *  略
 * </pre>
 */
abstract public class ActiveRecord<T>
{
    // 当前dao class
    protected BaseDao baseDao;

    // 对应的dao class
    protected Class<BaseDao> daoClass;

    // 对应的实体
    protected Class entityClass;

    public  BaseDao makeDao()
    {
        if (this.baseDao == null) {
            try {
                this.baseDao = this.daoClass.newInstance();
            } catch (Exception ex) {

            }
        }
    }

    public <T> T fetch(Long id)
    {
        BaseDao baseDao = this.makeDao();

        EntityMetadata entityMetadata = Entity.getEntity(this.entityClass);
        // 获取主键字段名称

        //SqlMap whereSqlMap =

        return (T)baseDao.where().setEntity(this.entityClass).one();
    }

}
